package day0106;

import static org.junit.Assume.assumeFalse;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class WhileFor {
	@Test
	public void test1() {
		int i = 1;
			while (i <= 5) {
				System.out.println("HelloWorld");
				i++;
			}
		}
	
	@Test
	public void test2() {
		for (int i = 0; i <= 5; i++) {
			System.out.println("HelloWorld");
		}
	}
	
	@Test
	public void test4() {
		int sum = 0;
		for (int i = 0; i <= 100; i++) {
			sum = sum + i;
		}
		System.out.println(sum);
	}
	
	@Test
	public void test5() {
		int i = 0;
		int sum = 0;
		while (i <= 100) {
			sum = sum + i;
			i++;
		}
		System.out.println(sum);
	}
	
	
	@Test
	public void test6() {
		int count = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 7 == 0) {
				count++;
			}
		}
		System.out.println("7的倍数的个数为" + count);
	}
	
	@Test
	public void test7() {
		int count = 0;
		int i = 1;
		while (i <= 100) {
			if (i % 7 == 0) {
				count++;
			}
			i++;
		}
		System.out.println("7的倍数的个数为" + count);
		}	
	
	
	
	@Test
	public void test8() {
		for (int i = 1; i <= 10; i++) {
			if (i == 5) {
				continue; //continue   跳出本次循环，继续下次循环
			}
			System.out.println(i);  // 除了5，其他都打印
		}
	}
	
	
	@Test
	public void test9() {
		for (int i = 1; i <= 10; i++) {
			if (i == 5) {
				break; //break  跳出离他最近的那次循环
			}
			System.out.println(i);  // 只打印1.2.3.4
		}
	}
	
	@Test
	public void test10() {
		for (int i = 1; i <= 10; i++) {
			System.out.println("i:" + i);
			for (int j = 1; j <= 10; j++) {
				if (j == 5) {
					break;
				}
				System.out.println("j:" + j);
			}
			
		}
	}
	
	@Test
	public void test11() {
		Scanner scanner = new Scanner(System.in);
		// Random随机，可以实现随即生成某个范围内的数
		Random random = new Random();
		// 返回值：下一个伪随机数，在此随机数生成器序列中 0（包括）和 n（不包括）之间均匀分布的 int 值。
		// [0, 100)  [0,99] + 1 = [1, 100]
		int randomNum = random.nextInt(100)+1;
		System.out.println(randomNum);
		// while(true)   for(; ;) 均为无限死循环
		while (true) {
			System.out.println("猜吧");
			int guess = scanner.nextInt();
			if (guess == 0) {
				System.out.println("退出成功");
				return;  //结束方法，后面代码不再执行
			} else {
				if (guess > randomNum) {
					System.out.println("太大了");
				} else if (guess < randomNum) {
					System.out.println("太小了");
				} else if (guess == randomNum) {
					System.out.println("恭喜你，猜对了");
				break;   // 跳出while死循环；
				}
			}
		}
	}
}

